<script setup lang="ts">
import DoctoberCart from './DoctoberCart.vue'
import { getDoctorPage } from '@/api/consult'
import type { DoctorPage, DoctorList } from '@/types/consult'
import { ref, onMounted } from 'vue'
const width = ref(150)
const setWidth = () => (width.value = (150 / 375) * window.innerWidth)
onMounted(() => {
  setWidth()
})
const doctorList = ref<DoctorList>([])
const getDoctorList = () => {
  getDoctorPage<DoctorPage>({ current: 1, pageSize: 5 }).then((res) => {
    doctorList.value = res.data.rows
  })
}
onMounted(() => {
  getDoctorList()
})
</script>
<template>
  <div class="follow-doctor">
    <div className="head">
      <p>推荐关注</p>
      <a href="javascript:;"> 查看更多<i class="van-icon van-icon-arrow" /></a>
    </div>
    <div class="body">
      <van-swipe :loop="false" :showIndicators="false" :width="width">
        <van-swipe-item v-for="item in doctorList" :key="item.id">
          <DoctoberCart :item="item"></DoctoberCart>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>
<style scoped lang="scss">
.follow-doctor {
  background-color: var(--cp-bg);
  height: 250px;
  .head {
    display: flex;
    justify-content: space-between;
    height: 45px;
    align-items: center;
    padding: 0 15px;
    font-size: 13px;
    > a {
      color: var(--cp-tip);
    }
  }
  .body {
    width: 100%;
    overflow: hidden;
  }
}
</style>
